﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Demo1.aspx.cs" Inherits="Demo1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            DeleteCommand="DELETE FROM [Categories] WHERE [CategoryID] = @CategoryID" 
    InsertCommand="INSERT INTO [Categories] ([CategoryName], [Description]) VALUES (@CategoryName, @Description)"
    SelectCommand="SELECT [CategoryID], [CategoryName], [Description], [Picture] FROM [Categories] WHERE CategoryName LIKE '%'+@CategoryName+'%'"
    UpdateCommand="UPDATE [Categories] SET [CategoryName] = @CategoryName, [Description] = @Description WHERE [CategoryID] = @CategoryID">
    <SelectParameters>
    <asp:ControlParameter ControlID="TextBoxCategoryName" Name="CategoryName" Type="String" PropertyName="Text" ConvertEmptyStringToNull="False"/>
    </SelectParameters>

        </asp:SqlDataSource>
        <br />
        <br />
    Query By CategoryName:
<asp:TextBox ID="TextBoxCategoryName" runat="server"></asp:TextBox>
<asp:Button ID="ButtonQuery" runat="server" Text="Query" />

<asp:GridView ID="GridView1" runat="server" Width="90%" AutoGenerateColumns="False" DataKeyNames="CategoryID" AllowPaging="true" PageSize="10"
DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
    <asp:CommandField ShowSelectButton="True" />
    <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
        ReadOnly="True" SortExpression="CategoryID" />
    <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
    <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
    <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
</Columns>
</asp:GridView>


<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="CategoryID" Width="90%"
DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" HeaderText="Details">
<Fields>
    <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName">
        <ItemStyle Width="90%" />
    </asp:BoundField>
    <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>

    </div>
    </form>
</body>
</html>
